//
//  MKLyricLabel.m
//  singForYou
//
//  Created by nicolas on 2016/12/15.
//  Copyright © 2016年 nicolas. All rights reserved.
//

#import "MKLyricLabel.h"

@implementation MKLyricLabel

- (void)drawRect:(CGRect)rect {
    // 将对象颜色 与 底层对象颜色混合
    
    // 1. 绘制文字
    [super drawRect:rect];
    
    // 2. 设置底层对象颜色
    [self.color setFill];
    
    // 3. 混合绘制
    CGRect newRect = CGRectMake(0, 0, rect.size.width * self.progress, rect.size.height);
    UIRectFillUsingBlendMode(newRect, kCGBlendModeSourceIn);
}

#pragma mark - Getter & Setter

- (void)setProgress:(CGFloat)progress {
    // 值范围必须是 0.0 ~ 1.0
    if (progress >= 0.0 && progress <= 1.0) {
        _progress = progress;
    }
    //刷新UI
    [self setNeedsDisplay];
}

- (UIColor *)color
{
    if (_color) {
        return _color;
    }
    return [UIColor yellowColor];
}
@end
